package com.cloud.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cloud.model.PaymentForm;
import com.cloud.model.query.PaymentPageQuery;
import com.cloud.model.vo.PaymentPageVO;
import com.cloud.service.PaymentService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cloud.common.result.PageResult;
import com.cloud.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;



/**
 * 支付表 前端控制器
 *
 * @author Sailer Wen
 * @since 2024-07-24
 */
@Tag(name = "支付表接口")
@RestController
@RequestMapping("/api/v1/payments")
@RequiredArgsConstructor
public class PaymentController {

        private final PaymentService paymentService;

        @Operation(summary = "支付表分页列表")
        @GetMapping("/page")
        public PageResult<PaymentPageVO> listPagedPayments(PaymentPageQuery queryParams ) {
            IPage<PaymentPageVO> result = paymentService.listPagedPayments(queryParams);
            return PageResult.success(result);
        }

        @Operation(summary = "新增支付表")
        @PostMapping
        public Result savePayment(@RequestBody PaymentForm formData ) {
            boolean result = paymentService.savePayment(formData);
            return Result.judge(result);
        }

        @Operation(summary = "支付表表单数据")
        @GetMapping("/{id}/form")
        public Result<PaymentForm> getPaymentForm(
            @Parameter(description = "支付表ID") @PathVariable Long id
        ) {
            PaymentForm formData = paymentService.getPaymentFormData(id);
            return Result.success(formData);
        }

        @Operation(summary = "修改支付表")
        @PutMapping(value = "/{id}")
        public Result updatePayment(@Parameter(description = "支付表ID") @PathVariable Long id,
        @RequestBody @Validated PaymentForm formData) {
            boolean result = paymentService.updatePayment(id, formData);
            return Result.judge(result);
        }

        @Operation(summary = "删除支付表")
        @DeleteMapping("/{ids}")
        public Result deletePayments(
            @Parameter(description = "支付表ID，多个以英文逗号(,)分割") @PathVariable String ids
        ) {
            boolean result = paymentService.deletePayments(ids);
            return Result.judge(result);
        }
}
